package org.bookr.engine.model;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Pawel Tomaszewski
 */
public class Book extends AbstractBookrEntity {
    protected String title, description;
    protected Category category;
    protected Set<Comment> comments = new HashSet<Comment>();
    protected Set<Author> authors = new HashSet<Author>();

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
//        category.addBook(this);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set<Comment> getComments() {
        return comments;
    }

    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }

    public Set<Author> getAuthors() {
        return authors;
    }

    public void setAuthors(Set<Author> authors) {
        this.authors = authors;
    }

    public void removeComment(Comment comment) {
        if(comments.contains(comment)) {
            comments.remove(comment);
            comment.setBook(null);
        }
    }

    public void addComment(Comment comment) {
        if(!comments.contains(comment)) {
            comments.add(comment);
            comment.setBook(this);
        }

    }

    public void removeAuthor(Author author) {
        if(authors.contains(author)) {
            authors.remove(author);
            author.removeBook(this);
        }
    }

    public void addAuthor(Author author) {
        if(!authors.contains(author)) {
            authors.add(author);
            author.addBook(this);
        }
    }
}
